package juc;

public class ThreadLocalTest
{

    public static void main(String[] args)
    {
        ThreadLocal<String> threadLocal = new ThreadLocal<>();
        new Thread(() ->
        {
            threadLocal.set("无敌");
            System.out.println(threadLocal.get()+"===="+Thread.currentThread().getName());
        },"A").start();
        new Thread(() ->
        {
            //threadLocal.set("无情");
            //注释掉上面的话以后，这个代码输出的结果为null，证明其是在多线程方面可以保留线程本身的变量
            System.out.println(threadLocal.get()+"===="+Thread.currentThread().getName());
        },"B").start();
        new Thread(() ->
        {
            //threadLocal.set("无语");
            System.out.println(threadLocal.get()+"===="+Thread.currentThread().getName());
        },"C").start();
    }

}
